﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_EShop._Class.BLL.GZ;

namespace V5_EShop
{
    public partial class ChkPwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = (V5_Model.ModelGZUser)Session["isLogin"];
            var type = Request["type"] + string.Empty;
            string pwd = Request["pwd"] + string.Empty;
            string fl = "0";

            if (user == null)
            {
                WriteMsg("请先登录！");
            }


            switch (type)
            {
                case "0":
                    fl = ChkUserPwd(user, pwd.Trim()) ? "0" : "旧密码错误！";
                    break;
                case "1":
                    SavePwd(user, pwd.Trim());
                    break;
                default:
                    WriteMsg("非法操作");
                    break;
            }
            WriteMsg(fl);
        }

        public bool ChkUserPwd(V5_Model.ModelGZUser user, string pwd)
        {
            var fl = false;

            if (user.Pwd == pwd)
                fl = true;

            return fl;
        }


        public void SavePwd(V5_Model.ModelGZUser user, string pwd)
        {
            user.Pwd = pwd;

            new BLLGZUser().Update(user);
        }


        private void WriteMsg(string info)
        {
            Response.Write(info);
            Response.End();
        }
    }
}